$(function(){

   
	//ajax通用表单提交
	$('.myform').submit(function(){
		var myform = $(this);
        $.ajax({
            url: myform.attr('action'),
            type: myform.attr('method'),
            data: myform.serialize(),
            success: function (info) {
                layer.msg(info.msg,{ico:1,time:2000},function(){
                	if(info.code === '00000'){ //跳转
                		location.href = info.url;
                	}else if(info.code === '00001'){//刷新
                		location.href = location.href;
                	}
                });
            }
        });
        return false;
	});


    /**
     * 通用删除
     */
    $('.ajax-delete').on('click', function () {
        var _href = $(this).attr('href');
        layer.open({
            shade: false,
            content: '确定删除？',
            btn: ['确定', '取消'],
            yes: function (index) {
                $.ajax({
                    url: _href,
                    type: "get",
                    success: function (info) {
		                 layer.msg(info.msg,{ico:1,time:2000},function(){
		                	if(info.code === '00000'){ //跳转
		                		location.href = info.url;
		                	}else if(info.code === '00001'){//刷新
		                		location.href = location.href;
		                	}
		                });
                    }
                });
                layer.close(index);
            }
        });

        return false;
    });
    
    
     /**
     * 通用确认
     */
    $('.ajax-ok').on('click', function () {
        var _href = $(this).attr('href');
        var _msg = $(this).data('msg');
        layer.open({
            shade: false,
            content: _msg,
            btn: ['OK', '取消'],
            yes: function (index) {
                $.ajax({
                    url: _href,
                    type: "get",
                    success: function (info) {
		                layer.msg(info.msg,{ico:1,time:2000},function(){
		                	if(info.code === '00000'){ //跳转
		                		location.href = info.url;
		                	}else if(info.code === '00001'){//刷新
		                		location.href = location.href;
		                	}
		                });
                    }
                });
                layer.close(index);
            }
        });
        return false;
    });




     /**
     * 通用A标签点击事件
     */
    $('.ajax-a').on('click', function () {
        var _href = $(this).attr('href');
        $.ajax({
            url: _href,
            type: "get",
            success: function (info) {
                layer.msg(info.msg,{ico:1,time:1000},function(){
                	if(info.code === '00000'){ //跳转
                		location.href = info.url;
                	}else if(info.code === '00001'){//刷新
                		location.href = location.href;
                	}
                });
            }
        });
        return false;
    });   
    
    
    
    /**
     * 通用全选
     */
    $('.check-all').on('click', function () {
        $(this).parents('table').find('input[type="checkbox"]').prop('checked', $(this).prop('checked'));
    });  

    /**
     * 通用批量处理（批量审核、取消审核、删除）
     */
    $('.ajax-action').on('click', function () {
        var _action = $(this).data('action');
        $.ajax({
            url: _action,
            data: $('.ajax-form').serialize(),
            success: function (info) {
                if (info.code === 1) {
                    setTimeout(function () {
                        location.href = info.url;
                    }, 1000);
                }
                layer.msg(info.msg);
            }
        });

        return false;
    });


});